﻿Ext.define('MyDesktop.App', {
    extend: 'Ext.ux.desktop.App',
    requires: [
        'Ext.window.MessageBox',
        'Ext.ux.desktop.ShortcutModel',
        'MyDesktop.frgbak',
		'MyDesktop.frgbclist',
        'MyDesktop.Settings',
		'Ext.data.*'
    ],
    init: function() {
		
        // custom logic before getXYZ methods get called...
        this.callParent();
        // now ready...
    },
    getModules : function(){
		var mepri = Ext.decode(Ext.getStore('userinfo_store').getRange()[0].get('privileges'));
		if ((mepri.system.admin)||(mepri.frgbak.admin)){
			return [
				new MyDesktop.frgbak(),
				new MyDesktop.frgbclist(),
				new MyDesktop.Settings()
			];
		}else if (Ext.Array.indexOf(mepri.system.index,'frgbak') >= 0){
			return [
				new MyDesktop.frgbak(),
				new MyDesktop.frgbclist()
			];
		}    
    },

    getDesktopConfig: function () {
        var me = this, ret = me.callParent();
		var mepri = Ext.decode(Ext.getStore('userinfo_store').getRange()[0].get('privileges'));
		if ((mepri.system.admin)||(mepri.frgbak.admin)){
			var data = [
						{ name: '富人国备份', iconCls: 'frgbak-shortcut', module: 'frgbak-win' },
						{ name: '富人国中心服列表', iconCls: 'frgbak-shortcut', module: 'frgbclist-win' },
						{ name: '系统设置', iconCls: 'systemsetting-shortcut', module: 'settings-win' }
					];
		}else if (Ext.Array.indexOf(mepri.system.index,'frgbak') >= 0){
			var data = [
						{ name: '富人国备份', iconCls: 'frgbak-shortcut', module: 'frgbak-win' },
						{ name: '富人国中心服列表', iconCls: 'frgbak-shortcut', module: 'frgbclist-win' },
					];
		}
        return Ext.apply(ret, {
            //cls: 'ux-desktop-black',
            shortcuts: Ext.create('Ext.data.Store', {
                model: 'Ext.ux.desktop.ShortcutModel',
                data: data
            }),

            wallpaper: '/images/wallpapers/desktop.jpg',
            wallpaperStretch: true
        });
    },

    // config for the start menu
    getStartConfig : function() {
        var me = this, ret = me.callParent();
		var username = Ext.getStore('userinfo_store').getRange()[0].get('name');
        return Ext.apply(ret, {
            title: username,
            iconCls: 'user',
            height: 300,
            toolConfig: {
                width: 100,
                items: [
                    {
                        text:'Logout',
                        iconCls:'logout',
                        handler: me.onLogout,
                        scope: me
                    },
					'-'
                ]
            }
        });
    },

    getTaskbarConfig: function () {
        var ret = this.callParent();

        return Ext.apply(ret, {
            /*quickStart: [
                { name: 'Accordion Window', iconCls: 'accordion', module: 'acc-win' },
                { name: 'Grid Window', iconCls: 'icon-grid', module: 'grid-win' }
            ],*/
            trayItems: [
                { xtype: 'trayclock', flex: 1 }
            ]
        });
    },
    onLogout: function () {
        Ext.Msg.confirm('Logout', '确定退出吗？',function(btn){
			if (btn == 'yes'){
				Ext.Ajax.request({
					url: '/interface.php',
					params: {
						type: 'logout'
					},
					success: function(response){
						if (response.responseText == 'success'){
							location.href="index.html";
						}else{
							Ext.Msg.alert('Logout', '退出失败！！');
						}
					}
				});
			}
		});
    }
});

